import AdaptationCom from './AdaptationCom';
/*
 * @Author: HanYaJun
 * @Date: 2023-01-06 11:52:51
 * @Email: hanyajun@wedobest.com.cn
 * @Description: 检测报告
 */

const trace = function (...args) {
    console.log('TestReport【HYJ】', ...args);
}

const traceError = function (...args) {
    console.error('TestReport【HYJ】', ...args);
}

const { ccclass, property } = cc._decorator;

@ccclass
export default class TestReport extends cc.Component {
    /**超越用户数 */
    private userRatio: cc.Node = null;
    /**提示信息 */
    private tip: cc.Node = null;
    /**说明信息 */
    private explain: cc.Node = null;
    /**顶部适配 */
    private top: cc.Node = null;
    /**虚拟列表 */
    private scrollView: cc.Node = null;
    /**遮罩 */
    private view: cc.Node = null;

    /**
     * @description: 当附加到一个激活的节点上或者其节点第一次激活时候调用
     */
    protected onLoad(): void {
        this.userRatio = cc.find('top/scrollView/view/content/topCount/yanLiLayout/userRatio', this.node);
        this.tip = cc.find('top/scrollView/view/content/topCount/tip', this.node);
        this.explain = cc.find('top/scrollView/view/content/topCount/explain', this.node);
        this.top = this.node.getChildByName('top');
        this.scrollView = cc.find('top/scrollView', this.node);
        this.view = cc.find('top/scrollView/view', this.node);
        this.initData();
    }

    /**
     * @description: 初始化数据
     */
    private initData(): void {
        // 滑动列表适配
        let screenSize = cc.view.getVisibleSize();
        if (this.scrollView) {
            let scrollNodeWidget: cc.Widget = this.scrollView.getComponent(cc.Widget);
            this.scrollView.height = screenSize.height - scrollNodeWidget.top;
            scrollNodeWidget.bottom = -screenSize.height;
            let view = this.view.getComponent(cc.Widget);
            // 立刻执行 widget 对齐操作
            view.updateAlignment();
        }
        // 获取关卡
        let level: number = null;
        // 用户超越百分比
        let userRatio: cc.Label = this.userRatio.getComponent(cc.Label);
        // 提示信息
        let tip: cc.Label = this.tip.getComponent(cc.Label);
        // 说明信息
        let explain: cc.Label = this.explain.getComponent(cc.Label);

        let progressLevel = cc.sys.localStorage.getItem('progressLevel');
        if (progressLevel) {
            level = parseInt(progressLevel);
        }
        // 信息展示
        if (level) {
            // 提示信息
            if (1 <= level && level <= 9) {
                tip.string = '请继续保持!';
                explain.string = '说明您对于颜色的分辨力较差,正常人的眼睛对于基础颜色的分辨一般在5S左右,您当前水准明显低于正常水准，请警惕色弱风险，若您非天生色弱，则需做进一步检查确定。';
            } else if (10 <= level && level <= 13) {
                tip.string = '有加强空间!';
                explain.string = '说明您现在目前眼睛状态有待加强,需要注意色弱风险,色弱在视觉障碍中属于程度较轻的,但若您有近视等其他情况，近期需要观察是否有出现明显的视力下降情况出现。';
            } else if (14 <= level && level <= 20) {
                tip.string = '需注意健康!';
                explain.string = '说明您目前眼睛状态良好,辨色能力未出现异常情况,继续保持您的眼睛状态,可以为您避免学习和生活中遇到不必要的麻烦哦。';
            }
            // 超越用户百分比
            if (level === 1) {
                userRatio.string = '40%';
            } else if (level === 2) {
                userRatio.string = '50%';
            } else if (level === 3) {
                userRatio.string = '55%';
            } else if (level === 4) {
                userRatio.string = '60%';
            } else if (5 <= level && level <= 9) {
                userRatio.string = '65%';
            } else if (10 <= level && level <= 11) {
                userRatio.string = '77%';
            } else if (level === 12) {
                userRatio.string = '82%';
            } else if (level === 13) {
                userRatio.string = '87%';
            } else if (14 <= level && level <= 16) {
                userRatio.string = '90%';
            } else if (17 <= level && level <= 18) {
                userRatio.string = '95%';
            } else if (19 <= level && level <= 20) {
                userRatio.string = '99%';
            }
        }
    }

    /**
     * @description: 关闭界面
     */
    public clickClose(): void {
        this.node.destroy();
    }

    /**
     * @description: 当该组件被销毁时调用
     */
    protected onDestroy(): void {

    }
}
